clear
set more off
capture log close
set matsize 10000

*Merge municipality data with kulturkampf data
do "prepare kulturkampf"

bysort district: egen median_afd = median(afd_share)
replace afd_share = median_afd if afd_share > 100

bysort district: egen median_catholic = median(catholic_share)
replace catholic_share = median_catholic if catholic_share > 100

label define prussia 1 "Prussia" 0 "Non Prussia"
label values prussia prussia

*********
*Figure1: Prussian borders in 1866, share of Catholics in 2011, and AfD vote shares in 2017
*********

grmap prussia if east == 0 using shapefile_germany_municipalities, id(ID) fcolor(Blues) clm(uniq) /// 
os(none none none none none none) ocolor(none none)  mos(none none none none none none) legend (position(2) size(med)) title ("Prussia") saving(fig1a, replace)

grmap catholic_share if east == 0 using shapefile_germany_municipalities, id(ID) fcolor(Blues) clm(custom) clbreaks(0 25 50 75 100) ///
os(none none none none none) ocolor(none none none none none) ndfcol(none) ndocol(none) legend (position(2) size(med)) title ("Share Catholics") ///
line(data("coord_prussia.dta") size(0.35) color(black)) saving(fig1b, replace)

grmap afd_share if east == 0 using shapefile_germany_municipalities, id(ID) fcolor(Blues) clm(custom) clbreaks(0 6 8 10 12 15 40) /// 
os(none none none none none none) ocolor(none none none none none) ndfcol(none) ndocol(none) legend (position(2) size(med)) title ("AfD Vote Share", ring(59)) ///
line(data("coord_prussia.dta") size(0.35) color(black)) saving(fig1c, replace)

graph combine fig1a.gph fig1b.gph fig1c.gph,  ///
	graphregion(c(white) lc(white)) ysize(8) xsize(16) row(1)
	
erase fig1a.gph 
erase fig1b.gph 
erase fig1c.gph

*********
*Figure 2: Intensity of Kulturkampf and share of Catholics with Volksverein membership in 1913
*********

grmap intensity_court if east == 0 using shapefile_germany_municipalities, id(ID) fcolor(Blues) clm(custom) /// 
clbreaks(0 0.5 2 5 10 20) os(none none none none none none none) ocolor(none none none none none none none) ndfcol(none) ndocol(none) ///
line(data("coord_prussia.dta") size(0.35) color(black)) legend (position(2) size(med)) title ("Kulturkampf Events per 100,000 Inhabitants", size(med)) saving(fig2a, replace)

grmap volksverein_1913 if east == 0 using shapefile_germany_municipalities, id(ID) fcolor(Blues) clm(custom) /// 
clbreaks(0 1.5 3 4 5 5.5 6 6.5 7) os(none none none none none none none none) ocolor(none none none none none none none none) ndfcol(none) ndocol(none) ///
line(data("coord_prussia.dta") size(0.35) color(black)) legend (position(2) size(med)) title ("Volksverein Members per 100 Catholics", size(med)) saving(fig2b, replace)

graph combine fig2a.gph fig2b.gph,  ///
	graphregion(c(white) lc(white)) row(1)
	
erase fig2a.gph 
erase fig2b.gph 

*********
*Figure 5: Rhineland-Palatinate in 1866, Catholic share in 2011 and AfD vote share in 2017
*********
 
gen colorscheme = 0
replace colorscheme = 1 if rlp_state == "Oldenburg"
replace colorscheme = 3 if rlp_state == "Bayern"
replace colorscheme = 5 if rlp_state == "Hessen-Darmstadt"
replace colorscheme = 7 if rlp_state == "Preußen"

grmap colorscheme if bundesland == "Rheinland-Pfalz"  using shapefile_germany_municipalities, ///
id(ID) fcolor(Blues) clm(custom) clbreaks(0 2 4 6 8) os(none none none none none none) mos(none none none none none none) ///
legend(label(2 "Birkenfeld") label(3 "Bavaria") label(4 "Hesse") label(5 "Prussia") size(med)) title("State Borders") ///
saving(fig5a, replace)

grmap catholic_share if bundesland == "Rheinland-Pfalz" using shapefile_germany_municipalities, ///
id(ID) fcolor(Blues) clm(custom) clbreaks(0 25 50 75 100) os(none none none none none none) mos(none none none none none none) legend(size(med)) title("Share Catholics") ///
line(data("coord_rlp.dta") size(0.3) color(black)) saving(fig5b, replace)

grmap afd_share if bundesland == "Rheinland-Pfalz" using shapefile_germany_municipalities, ///
id(ID) fcolor(Blues) clm(custom) clbreaks(0 4 8 12 15 40) os(none none none none none none) mos(none none none none none none) legend(size(med)) title("AfD Vote Share") ///
line(data("coord_rlp.dta") size(0.3) color(black)) saving(fig5c, replace)

graph combine fig5a.gph fig5b.gph fig5c.gph,  ///
	graphregion(c(white) lc(white)) ysize(6) xsize(14) row(1)

erase fig5a.gph 
erase fig5b.gph 
erase fig5c.gph
